

import dao.UserDaoImplMysql;
import dao.UserDaoImplRedis;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import service.UserService;
import service.UserServiceImplBefore;
import service.UserServiceImplNow;

/**
 * @author 15965
 */
public class Main {
    public static void main(String[] args) {

        // 传统方式测试, 传统方式bean的创建由service层完成
        UserService userService = new UserServiceImplBefore();
        // 这里的是从mysql中取出数据，加入现在需要从redis中取出数据，那么就需要去修改UserServiceImplBefore中的代码
        userService.getUserByID();

        // 改进后方式测试
        UserService us = new UserServiceImplNow();
        ((UserServiceImplNow) us).setUserDAO(new UserDaoImplMysql());
        us.getUserByID();

        ((UserServiceImplNow) us).setUserDAO(new UserDaoImplRedis());
        us.getUserByID();

        // create and configure beans
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");

        // retrieve configured instance
        UserService service = context.getBean("userService", UserServiceImplNow.class);
        UserService service2 = context.getBean(UserServiceImplNow.class);
    }
}
